<?php
include_once '../includes/common.php';
if($islogin==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
$proid=daddslashes($_GET['proid']);
$authcode=daddslashes($_GET['authcode']);
$sign=daddslashes($_GET['sign']);
if(!$proid || !$authcode){
    sysmsg("下载失败，请重试",2,'./authlist.php',true);
}
$program = $DB->get_row("select * from authguao_program where id='" . $proid . "' limit 1");
if($program){
    $site = $DB->get_row("select * from authguao_site where proid='" . $proid . "' and authcode='" . $authcode . "' limit 1");
    if($site){
        require_once(SYSTEM_ROOT.'pclzip.php');
        $file_real=substr($authcode,0,16).'.zip';
        $file=ROOT.CACHE_DIR."/{$file_real}";
        if($_GET['my']=='installer') {
            $file_path=ROOT.PACKAGE_DIR.'/'.$program['catalog'].'/release6000/';
            $file_str=file_get_contents(ROOT.PACKAGE_DIR.'/authcode.php');
            $file_str=str_replace('1000000001',$authcode,$file_str);
            file_put_contents($file_path.$program['authfile'],$file_str);
            $file_name=$program['installer_name'].'_'.rand(111111,999999).'.zip';
        }elseif($_GET['my']=='updater') {
            $file_path=ROOT.PACKAGE_DIR.'/'.$program['catalog'].'/update6000/';
            $file_str=file_get_contents(ROOT.PACKAGE_DIR.'/authcode.php');
            $file_str=str_replace('1000000001',$authcode,$file_str);
            file_put_contents($file_path.$program['authfile'],$file_str);
            $file_name=$program['updater_name'].'_'.rand(111111,999999).'.zip';
        }
        if(file_exists($file))unlink($file);
        $zip = new PclZip($file);
        $v_list = $zip->create($file_path ,PCLZIP_OPT_REMOVE_PATH,$file_path);
        $file_size=filesize("$file");
        header("Content-Description: File Transfer");
        header("Content-Type:application/force-download");
        header("Content-Length: {$file_size}");
        header("Content-Disposition:attachment; filename={$file_name}");
        readfile("$file");
    }else{
        sysmsg("未存在该授权",2,'./authlist.php',true);
    }
}else{
    sysmsg("该程序可能不存在",2,'./authlist.php',true);
}
?>